﻿/// <reference path="../../_references.js" />
(function (e) {

    //TODO: refactor and apply Ko for entire view
    e.views = e.views || {};
    e.views.companies = e.view.define({
        templateName: "tmpl_companies",
        repo: null,
        load: function (state) {
            var that = this;
            this.repo = new e.repositories.company();
            this.repo.getAllCompanies(function (err, data) {
                if (!err)
                    that.displayCompanies(data);
            });
        },
        displayCompanies: function (data) {
            var that = this;
            this.render({
                companies: data,
                deleteCompany: function () {
                    if (confirm(loc.deleteCompanyConfirm)) {
                        that.repo.deleteCompany(this.Id, function (err) {
                            if (!err) {
                                e.flash.success("Company deleted successfully.");
                                that.load();
                            }
                        });

                    }
                }
            });
        }
    });
} (this.eg = this.eg || {}));